# Archlive <http://archlive-pkg.googlecode.com>

pkgname=ndiswrapper
_kernver=$(uname -r)
pkgver=2723
pkgrel=1
pkgdesc="Module for NDIS (Windows Network Drivers) drivers supplied by vendors. For stock arch 2.6 kernel."
license=('GPL')
arch=(i686 x86_64)
url="http://ndiswrapper.sourceforge.net"
install="ndiswrapper.install"
depends=('kernel26')
conflicts=("ndiswrapper" "ndiswrapper-utils")
provides=("ndiswrapper=$pkgver" "ndiswrapper-utils=$pkgver")
source=(module-init-tools.patch)
md5sums=()

_svntrunk=https://ndiswrapper.svn.sourceforge.net/svnroot/ndiswrapper/trunk/ndiswrapper
_svnmod=ndiswrapper

build()
{
  cd ${srcdir}

  if [ -d $_svnmod/.svn ]; then
    (cd $_svnmod && svn up -r $pkgver)
  else
    svn co $_svntrunk --config-dir ./ -r $pkgver $_svnmod
  fi

  msg "SVN checkout done or server timeout"
  msg "Starting make..."

  [ -d ${srcdir}/${_svnmod}-build ] && rm -rf ${srcdir}/${_svnmod}-build
  cp -r ${srcdir}/$_svnmod ${srcdir}/${_svnmod}-build

  cd ${srcdir}/${_svnmod}-build/driver
  make KVERS=$_kernver || return 1
  make DESTDIR=$pkgdir KVERS=$_kernver install || return 1
  rm $pkgdir/lib/modules/$_kernver/modules.* #wtf?

  sed -i -e "s/KERNEL_VERSION='.*'/KERNEL_VERSION='${_kernver}'/" $startdir/*.install
  # move it to correct kernel directory
  mkdir -p $pkgdir/lib/modules/$_kernver/kernel/drivers/net/wireless/ndiswrapper
  mv $pkgdir/lib/modules/$_kernver/misc/* $pkgdir/lib/modules/$_kernver/kernel/drivers/net/wireless/ndiswrapper/
  rm -r $pkgdir/lib/modules/$_kernver/misc/

  cd ${srcdir}/${_svnmod}-build/utils
  # fix module init tools config file
  patch -Np0 -i ../../module-init-tools.patch || return 1
  make || return 1
  make DESTDIR=$startdir/pkg install
}
